home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / sa-book.zip / dumdum < prev    next >
Text File  |  1989-09-27  |  5KB  |  209 lines

  1. #!/bin/csh -f 
  2. # dumdum: script to do incremental dumps 
  3. #
  4.  
  5. onintr quit
  6. umask 7
  7.  
  8. # filesystems to be dumped on level 0 and 1
  9. set LOLEV =  "root usr net"
  10.  
  11. # filesystems to be dumped at every level
  12. set ALWAYS = "usr net"
  13.  
  14. # dump program to use 
  15. set DUMP = "/etc/dump"
  16.  
  17. # restore program to use
  18. set RESTORE = "/etc/restore"
  19.  
  20. # density of the tape
  21. set DEN = "1600"
  22.  
  23. # device to dump to
  24. set DUMPDEV = "/dev/mt0"
  25.  
  26. #directory where all dump information is stored
  27. set DUMPDIR = "/usr/local/adm/dumpdir"
  28. cd ${DUMPDIR}
  29.  
  30. #set up temporary file names
  31. set FLAGDIR = "${DUMPDIR}/flagdir"
  32. if (!(-d $FLAGDIR )) mkdir $FLAGDIR 
  33. set FLAGFILE = "${FLAGDIR}/dumpit"
  34. set FNAME = "tmp"
  35. set TEMPFILE = "${FLAGDIR}/${FNAME}$$"
  36.  
  37. # get the sequence information from the WHICHDUMP file
  38. set which = `cat ${DUMPDIR}/WHICHDUMP`
  39. set DATEFILE = "${DUMPDIR}/DUMPDATES"
  40. @ lessone = ${#which} - 1
  41. set nonomatch
  42.  
  43. start:
  44.  
  45. #if the last dump did not finish, restart it
  46. set junk = (`ls ${FLAGDIR}`)
  47. set isnotdone = (${junk})
  48. if (${#isnotdone} >= 1) then
  49.     echo "THIS IS THE CONTINUATION OF AN ABORTED DUMP"
  50.     echo "Continuing with a level ${which[${which[${#which}]}]} dump."
  51.     echo " "
  52.     echo -n "Is this correct? "
  53.     set junk = $<
  54.     while ((${junk} != "yes") && (${junk} != "no") &&  \
  55.         (${junk} != "y") && (${junk} != "n"))
  56.         echo -n "Please answer yes or no: "
  57.         set junk = $<
  58.     end
  59.     if ((${junk} == "n") || (${junk} == "no")) then
  60.         rm -f ${FLAGDIR}/*
  61.         goto start
  62.     endif
  63.     set restart
  64.     goto getlevel
  65. else
  66.  
  67. # increment the position counter (last element of array)
  68.     @ which[$#which]++
  69.  
  70. # if the position counter points to its own position in the array, recycle
  71. # back to the beginning of the array
  72.     if (${which[${#which}]} == ${#which}) set which[${#which}] = 1
  73. recover:
  74.     echo ""
  75.     echo -n "My records"
  76.     if (${?limit}) echo -n " now"
  77.     echo -n " indicate that this should be a "
  78.     echo " level ${which[${which[${#which}]}]} dump."
  79.     echo -n "Is this correct? "
  80.     set junk = $<
  81.     while ((${junk} != "yes") && (${junk} != "no") &&  \
  82.           (${junk} != "y") && (${junk} != "n"))
  83.         echo -n "Please answer yes or no: "
  84.         set junk = $<
  85.     end
  86.     if ((${junk} == "yes") || (${junk} == "y")) then
  87.         echo $which > ${DUMPDIR}/WHICHDUMP
  88.  
  89. # set the level - lolevel contains the number without sublevel information
  90. getlevel:
  91.         set level = ${which[${which[${#which}]}]}
  92.         set lolevel = `echo $level | tr -d "a-z"`
  93.     else
  94. #
  95. # list the dump sequence and corresponding numbers
  96. #
  97.         echo ""
  98.  
  99.         @ limit = $#which /  5 
  100.         set counter = 1
  101.         while ($counter <= $limit) 
  102.             set temp = $counter;
  103.             set i = 1
  104.                 while ($i <= 5) 
  105.                     echo -n "${temp}==$which[$temp]"
  106.                     if ($temp == $which[$#which]) then
  107.                         echo -n "*"
  108.                     endif
  109.                     echo -n "    "
  110.                     @ temp += 9;
  111.                     @ i++
  112.                 end
  113.                 echo ""
  114.                 @ counter++;
  115.         end
  116.  
  117.         echo "* marks the dumps I thought we were supposed to do."
  118.         echo ""
  119.         echo -n "What is the number of the correct dump? "
  120.  
  121.  
  122. # get the correct dump number
  123.         set junk = $<
  124.         while ((${junk} < "1") || (${junk} >= "${#which}"))
  125.             echo "Please choose a number between 1 and ${lessone}\!"
  126.             echo -n "What is the number of the correct dump? "
  127.             set junk = $<
  128.         end
  129.         set which[${#which}] = ${junk}
  130.         goto recover
  131.     endif
  132. endif
  133.  
  134. echo ""
  135.  
  136. if ((${lolevel} == "0") || (${lolevel} == "1")) then
  137.     set fs = "${LOLEV}"
  138. else
  139.     set fs = "${ALWAYS}"
  140. endif
  141.  
  142. echo "Doing these file systems: $fs"
  143.  
  144. echo " "
  145.  
  146. # cycle for each filesystem that needs to be done
  147. foreach filesystem ( ${fs} )
  148.     if (!(-e ${FLAGFILE}.${filesystem})) then
  149.         unset restart
  150.  
  151. #look up raw device name in /etc/fstab
  152.         if ($filesystem == "root") then
  153.             set DEV = `awk -F: '$2 ~ /\/$/ { print $1}'\
  154.                  /etc/fstab`
  155.         else
  156.             set DEV = `awk -F: '$2 ~ /'${filesystem}'$/\
  157.                  { print $1}' /etc/fstab`
  158.         endif
  159.  
  160. #do the dump
  161.         echo -n "Type 'yes' when the /${filesystem} tape is online: "
  162.         set junk=$<
  163.         while ((${junk} != "yes") && (${junk} != "y"))
  164.             echo -n "Type 'yes' when the /$filesystem tape is online:"
  165.             set junk=$<
  166.         end
  167.  
  168.         echo "Doing the dump...."
  169.         ${DUMP} ${lolevel}udf ${DEN} ${DUMPDEV} ${DEV} |& tee $TEMPFILE
  170.  
  171.         touch ${FLAGFILE}.${filesystem}
  172.  
  173.     else
  174.         echo "Apparently the ${filesystem} dump has been done."
  175.     endif
  176.  
  177. # do the dumptoc
  178.     if (!(-e ${FLAGFILE}.r${filesystem})) then
  179.  
  180.         echo -n "Doing the dumptoc..."
  181.         ${RESTORE} tf ${DUMPDEV} > ${DUMPDIR}/lev${level}.${filesystem}
  182.         touch ${FLAGFILE}.r${filesystem}
  183.         echo "Done"
  184.         if (-z ${DUMPDIR}/lev${level}.${filesystem}) then
  185.             echo "PANIC\!"
  186.             echo "${DUMPDIR}/lev${level}.${filesystem} is empty\!"
  187.         endif
  188.         echo -n "Level ${level} /${filesystem}       " >> ${DATEFILE}
  189.         echo -n `date` >> ${DATEFILE}
  190.         echo " by ${USER}" >> ${DATEFILE}
  191.     else
  192.         echo "And the dumptoc for ${filesystem} has been done also."
  193.     endif
  194. end
  195.  
  196. rm -f ${FLAGFILE}.*
  197.     
  198. goto clean
  199.  
  200. quit:
  201. echo ""
  202. echo "The dump has been killed.... I hope you know what you are doing\!"
  203. echo ""
  204.  
  205. clean:
  206. rm -f ${FLAGDIR}/${FNAME}*
  207. cd
  208.